package ms.pms.controller;

import ms.common.exception.BizException;
import ms.common.util.string.StringUtil;
import ms.pms.bean.LoginParamBean;
import ms.pms.config.ResponseCode;
import ms.pms.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Project Name: ms
 * File Name: LoginController
 * Package Name: ms.pms.controller
 * Date: 2018/6/21  18:22
 * Copyright (c) 2018, tianyul All Rights Reserved.
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * 登录
     * @param loginParamBean
     * @return
     */
    @PostMapping("/sign")
    public Map<String,Object> sign(@RequestBody LoginParamBean loginParamBean) {
        if(StringUtil.isEmpty(loginParamBean.getAccount())) {
            throw new BizException(ResponseCode.PARAM_ILLEGAL_ERROR, "账号不能为空");
        }
        if(StringUtil.isEmpty(loginParamBean.getPwd())) {
            throw new BizException(ResponseCode.PARAM_ILLEGAL_ERROR, "密码不能为空");
        }
        return loginService.sign(loginParamBean);
    }
}
